﻿openPopupMenu = function(eid)
{
    var popup = $id("nf_notif_popup");
    popup.className = "nf_notif_popup_hover";
    
    var content = $id("popup_content");
    var mode = eid.id.replace("si_","");
    
    var hid_event = $id("hidOpenPopup_event");
    var hid_notif = $id("hidOpenPopup_notif");
    
    if( mode == "notif" )
    {
        var x = parseInt(hid_notif.value);
        x = (x + 1) % 2;
        hid_notif.value = x;
        
        if( x == 0 )
        {
            hid_event.value = x;
            content.innerHTML = "";
            closePopupMenu();
            return;
        }
        else
        {
            hid_event.value = 0;
        }
        
    }
    else if( mode == "event" )
    {
        var y = parseInt(hid_event.value);
        y = (y + 1) % 2;
        hid_event.value = y;
        
        if( y == 0 )
        {
            hid_notif.value = y;
            content.innerHTML = "";
            closePopupMenu();
            return;
        }
        else
        {
            hid_notif.value = 0;
        }
        
    }
    
    content.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    
    var url = "ASHX/Notifications.ashx?action=" + mode;    var ajx = sendAJAX(url,true);
    ajx.onreadystatechange = function() {        if (ajx.readyState == 4) {                    var content = $id("popup_content");
            content.innerHTML = ajx.responseText;
            
            if( mode == "notif" )
            {
                // reset counter
                var counter = $id("cnt_" + mode);
                counter.innerHTML = "";
                
                // change icon
                var image = $id("img_" + mode);
                image.src = "images/" + mode + "0.png";            }        }    }
}

closePopupMenu = function()
{
    var popup = $id("nf_notif_popup");
    popup.className = "nf_notif_popup";
}

tmrDefault_c_Tick = function(s,e){
    var url = "ASHX/Notifications.ashx?action=update";    var ajx = sendAJAX(url,true);
    ajx.onreadystatechange = function() {        if (ajx.readyState == 4) {                    var ctr = $id("cnt_notif");
            var image = $id("img_notif");
            
            var ctr2 = $id("cnt_event");
            var image2 = $id("img_event");
            
            var sxSplitted = ajx.responseText.split(DELIMITER);
            
            if( sxSplitted[0] == "0" )
            {
                ctr.innerHTML == "";
                image.src = "images/notif0.png";
            }
            else
            {
                image.src = "images/notif.png";        
                ctr.innerHTML = sxSplitted[0];
            }                        if( sxSplitted[1] == "0" )
            {
                ctr2.innerHTML == "";
                image2.src = "images/event0.png";
            }
            else
            {
                image2.src = "images/event.png";        
                ctr2.innerHTML = sxSplitted[1];
            }        }    }
}